var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/help/MetricsHelp.tsx
var MetricsHelp_exports = {};
__export(MetricsHelp_exports, {
  MetricsHelp: () => MetricsHelp,
  default: () => MetricsHelp_default
});
module.exports = __toCommonJS(MetricsHelp_exports);
var import_react = __toESM(require("react"));
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_query_panel = require("../query-panel");
var import_common = require("./common");
var { Flex, Slider } = import_util.Layout;
var { Header, Footer, MultipleButtons } = import_functionalComponent.BaseHelp;
var tableProps = {
  rowSelected: false,
  rowChecked: true,
  cache: false,
  headerMenu: false,
  style: { borderStyle: "solid", borderColor: "var(--border-color-split, #f0f0f0)", borderWidth: 1 }
};
var FilterTree = ({ onSelectedChange }) => {
  function convertTreeResultsToTreeNodes(treeResults) {
    return treeResults.map(convertTreeResultToTreeNode);
  }
  function convertTreeResultToTreeNode(treeResult) {
    const { id, metricName, children, currentLevel } = treeResult;
    const treeNode = {
      key: id,
      title: metricName,
      currentLevel
    };
    if (children && children.length > 0) {
      treeNode.children = convertTreeResultsToTreeNodes(children);
      treeNode.isLeaf = false;
    } else {
      treeNode.isLeaf = true;
    }
    return treeNode;
  }
  const treeRequest = (0, import_util.useRefCallback)(async () => {
    const curEnv = import_util.iup.getQueryValue("env") || "prod";
    return import_util.iup.request.get({
      url: curEnv === "dev" ? "/engine/metricTreeDesign/all" : "/engine/metricTree/all"
    }).then((res) => {
      const result = convertTreeResultsToTreeNodes(res.data);
      console.log("result, ", result);
      return result;
    });
  });
  return /* @__PURE__ */ import_react.default.createElement(import_functionalComponent.AsyncTree, { request: treeRequest, onSelectedChange, virtual: true });
};
function HelpContent() {
  const {
    request,
    ok,
    contentParams: { getFieldValue, columns, helpTitle, helpId, selectedArray, multiple, footer },
    randomKey
  } = (0, import_react.useContext)(import_functionalComponent.HelpContext);
  const btnRef = (0, import_react.useRef)();
  const formRef = (0, import_util.useApi)();
  const [activeKey, setActiveKey] = (0, import_react.useState)("0");
  const rightTable = (0, import_react.useRef)();
  const getTable = () => import_util.iup.compIns[`${helpId}_${randomKey}_${activeKey}`].getApi();
  const getResult = () => {
    if (multiple) {
      const result = rightTable.current.getApi().getRows().map((r) => ({
        value: getFieldValue(r),
        label: getFieldValue(r, "label"),
        origin: { ...r }
      }));
      return result.length > 0 ? result : void 0;
    } else {
      const value = getTable().getSelectedData()[0];
      if (value) {
        return { value: getFieldValue(value), label: getFieldValue(value, "label"), origin: { ...value } };
      }
      return void 0;
    }
  };
  const toRight = (values) => {
    if (multiple) {
      btnRef.current.toRight(values);
    } else {
      ok(getResult());
    }
  };
  const onSelectCallback = (0, import_util.useRefCallback)((keys, nodes) => {
    getTable().setExtraParam({ treeNodes: nodes });
  });
  const queryItems = (0, import_react.useMemo)(
    () => [
      {
        name: "metricName",
        label: "指标名称"
      }
    ],
    []
  );
  tableProps.checkbox = multiple ? "checked" : false;
  tableProps.rowSelected = !multiple;
  tableProps.rowChecked = multiple;
  const renderTable = (index) => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_functionalComponent.Table,
      {
        ...tableProps,
        style: { ...tableProps.style },
        id: `${helpId}_${randomKey}_${index}`,
        columns,
        onRow: (rowIndex, table) => ({
          onDoubleClick: () => toRight([table.getRow(rowIndex)])
        }),
        autoLoad: false,
        request,
        pagination: {
          height: 32,
          showQuickJumper: false,
          align: "left",
          targetContainer: multiple && index === 0 ? `${helpId}_${randomKey}_pagination` : ""
        },
        response: (res) => ({ total: res.total ?? 0, record: res.list || [] })
      }
    );
  };
  return /* @__PURE__ */ import_react.default.createElement(import_util.Layout, null, /* @__PURE__ */ import_react.default.createElement(Header, { title: helpTitle || "指标帮助" }), /* @__PURE__ */ import_react.default.createElement(Flex, { direction: "row", style: { padding: "5px 5px 0 5px" } }, /* @__PURE__ */ import_react.default.createElement(Slider, { size: 200, style: { margin: "0 var(--inner-margin, 16px) 0 0" } }, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Panel,
    {
      title: "指标分类树",
      autoFit: true,
      style: { ...(0, import_util.borderStyle)() },
      bodyStyle: { padding: "var(--inner-padding, 8px)" }
    },
    /* @__PURE__ */ import_react.default.createElement(FilterTree, { onSelectedChange: onSelectCallback })
  )), /* @__PURE__ */ import_react.default.createElement(Flex, { direction: "column" }, /* @__PURE__ */ import_react.default.createElement(import_query_panel.QueryPanel, { items: queryItems, gridRef: `${helpId}_${randomKey}_0` }), /* @__PURE__ */ import_react.default.createElement(Flex, { direction: "row", style: { marginTop: -11 } }, /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, { style: { paddingBottom: multiple ? 32 : 0 } }, renderTable(0)), multiple && /* @__PURE__ */ import_react.default.createElement(
    MultipleButtons,
    {
      getRowKey: getFieldValue,
      outRef: btnRef,
      getActiveTable: getTable,
      getResultTable: () => rightTable.current.getApi()
    }
  ), multiple && /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, { style: { paddingTop: 7, paddingBottom: activeKey === "0" ? 32 : 0 } }, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Table,
    {
      ...tableProps,
      columns,
      dataSource: selectedArray,
      ref: rightTable,
      onRow: (rowIndex) => ({
        onDoubleClick: () => btnRef.current.toLeft(rowIndex)
      })
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      id: `${helpId}_${randomKey}_pagination`,
      style: {
        position: "absolute",
        left: 221,
        right: 5,
        ...(0, import_util.borderStyle)(["left", "right", "bottom"]),
        paddingLeft: 10
      }
    }
  ))))), /* @__PURE__ */ import_react.default.createElement(Footer, { getResult }, footer && /* @__PURE__ */ import_react.default.createElement("span", { style: { flex: 1, width: 0 }, children: footer })));
}
var MetricsHelp = (0, import_util.compHoc)((props) => {
  const cacheHelpInfo = (0, import_react.useRef)({ data: null, p: null });
  const {
    valueField = "metricCode",
    labelField = "metricName",
    displayField,
    userCodeField,
    clientSqlFilter,
    title,
    multiple = false,
    modalProps,
    footer,
    metricsRequest,
    metricsParams = {},
    columns,
    onBeforeOpen,
    ...others
  } = props;
  const otherProps = others;
  const curEnv = import_util.iup.getQueryValue("env") || "prod";
  otherProps.onBeforeOpen = (0, import_util.useRefCallback)(async () => {
    const [status, helpInfo] = await (0, import_common.getHelpBeforeOpen)({ onBeforeOpen, cacheHelpInfo });
    if (import_util.iup.isObject(helpInfo)) {
      return helpInfo;
    }
    return status;
  });
  otherProps.request = (0, import_util.useRefCallback)(async ({ pageIndex, pageSize, params, treeNodes, ...queryFilter }) => {
    if (treeNodes && treeNodes.length > 0) {
      queryFilter["metricTreeId"] = treeNodes[0].key;
    }
    const data = {
      ...params,
      pageNum: pageIndex,
      pageSize,
      metricStatus: 1,
      ...queryFilter
    };
    console.log(data);
    if (metricsRequest) {
      return await metricsRequest(data);
    }
    return import_util.iup.request.body({
      url: curEnv === "dev" ? "/engine/metricDefDesign/pageMetricDef" : "/engine/metricDef/pageMetricDef",
      data
    }).then((res) => {
      if ((res == null ? void 0 : res.code) === 0) {
        return res == null ? void 0 : res.data;
      } else {
        return { list: [], total: 0 };
      }
    });
  });
  otherProps.valueField = valueField;
  otherProps.userCodeField = userCodeField;
  otherProps.labelField = labelField || displayField;
  otherProps.contentParams = {
    footer,
    multiple,
    valueField,
    labelField: otherProps.labelField,
    columns: columns ?? [
      { dataIndex: "metricName", title: "指标名称" },
      { dataIndex: "metricCode", title: "指标编码" },
      {
        dataIndex: "bizMetricType",
        title: "指标类型",
        tooltip: true,
        render: ({ row }) => {
          const value = row.bizMetricType;
          if (value === "1" || value === 1) {
            return "原子指标";
          } else if (value === "2" || value === 2) {
            return "派生指标";
          } else if (value === "3" || value === 3) {
            return "复合指标";
          } else {
            return "";
          }
        }
      },
      {
        dataIndex: "mgrIsCore",
        title: "核心指标",
        tooltip: true,
        render: ({ row }) => {
          const value = row.mgrIsCore;
          if (value) {
            return "是";
          } else {
            return "否";
          }
        }
      }
    ]
  };
  if (title) {
    otherProps.contentParams.helpTitle = title;
  }
  const { width, height } = (0, import_util.getGlobalConfig)().default.helpConfig;
  return /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.BaseHelp,
    {
      ...otherProps,
      modal: true,
      helpContent: HelpContent,
      multiple,
      modalProps: { width, height, ...modalProps }
    }
  );
}, "MetricsHelp");
var MetricsHelp_default = MetricsHelp;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  MetricsHelp
});
